#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

// 注意以下二者的区别：

struct Student { // 结构体名是可以省略的
    int number;
    bool gender;
    char name[20];
    float height;
    float weight;
} student; // 在定义结构体的同时定义了一个名为student的结构体变量

typedef struct { // 使用类型定义typedef给结构体起别名
    int number;
    bool gender;
    char name[20];
    float height;
    float weight;
} Student; // Student是结构体类型的别名

typedef struct node {
    int num;
    struct node * next;
} Node;

static Node arr[3] = {5, &arr[1], 7, &arr[2], 9, &arr[0]}, *pn = arr;

void size() {
    printf("student size = %d\n", sizeof(Student)); // char[20]占20字节，int bool float各占4字节
    printf("int size = %d\n", sizeof(int));
    printf("long int size = %d\n", sizeof(long)); // 4
    printf("short int size = %d\n", sizeof(short int)); // 2
    printf("float size = %d\n", sizeof(float)); // 4
}

struct MyStruct {
	int x;
	char* y;
	struct MyStruct* p;
}a[] = { {1, "pascal", 0}, {3, "basic", 0} };

void func() {
	struct MyStruct* ptr = a;
	char c, * s;
	s = ++ptr->y;
	printf("%s, ", s);
	s = ++ptr->y;
	printf("%s, ", s);
    
    // . -> 的优先级最高， -> 等价于 (*).

	c = *ptr->y; // *(ptr->y)
	printf("%c, ", c);
	c = *ptr++->y; // *((ptr++)->y)，->作用于结构体指针变量，*(ptr->y)，ptr++
	printf("%c, ", c);
	c = *ptr->y++; // *(ptr->y)++ 即 *(ptr->y), (ptr->y)++
	printf("%c, ", c);
	c = *ptr->y;
	printf("%c\n", c);
}

int main() {
    struct Student s1 = {1, 1, "zs"};
    struct Student s2 = {1, 1, 180, 150};
    // s2.name = "ls"; // 错误，数组只能在初始化时对整体赋值
    strcpy(s2.name, "ls");
    struct Student * p = &student;
    Student s3; // 使用别名声明变量
    printf("%6.2f, %6.2f\n", s1.height, s1.weight);
    printf("%s\n", s2.name);
    printf("%d\n", p->number);
    printf("%d\n", s3.gender);

    size();

    // Student s[5] = {s1, s2, s3};
    printf("%d, ", pn++->num), pn = arr, arr[0].num = 5;
    printf("%d, ", pn->num++), pn = arr, arr[0].num = 5;
    printf("%d, ", (*pn).num++), pn = arr, arr[0].num = 5;
    printf("%d\n", ++pn->num), pn = arr, arr[0].num = 5;
    
    func();
    return 0;
}